package com.yaorange.jk.web.shiro;

import com.yaorange.jk.utils.Encrypt;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;

public class CustomCredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo authenticationInfo) {
        System.out.println("密码比较中.......");

        UsernamePasswordToken t = (UsernamePasswordToken) token;
        char[] password = t.getPassword();
        String clientPwd = new String(password);
        String dbPwd = (String)authenticationInfo.getCredentials();
        String jm = Encrypt.md5(clientPwd, t.getUsername());
        return dbPwd.equals(jm);

    }
}
